package com.tjbklx1.thread.chap01.practice06;

public class Main {

	public static void main(String[] args) {

		// test01();

		// test02();

		System.out.println("Test eat ......");
		Tool spoon = new Tool("spoon");
		Tool fork = new Tool("fork");
		Pair pair = new Pair(spoon, fork);

		// 解决方法二 ： 成对获取资源
		new EaterThread2("Alice", pair).start();
		new EaterThread2("Bob", pair).start();
	}

	private static void test02() {
		System.out.println("Test eat ......");
		Tool spoon = new Tool("spoon");
		Tool fork = new Tool("fork");

		// 解决方法一 ： 以相同的顺序取资源
		new EaterThread("Alice", spoon, fork).start();
		new EaterThread("Bob", spoon, fork).start();
	}

	private static void test01() {
		System.out.println("Test eat ......");
		Tool spoon = new Tool("spoon");
		Tool fork = new Tool("fork");

		// 以不同的顺序取资源 会发生死锁
		new EaterThread("Alice", spoon, fork).start();
		new EaterThread("Bob", fork, spoon).start();
	}
}
